﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace QFlow.Data
{
    public static class OrderStatusExtension
    {
        private static OrderStatus _Canceled, _Adjusted;
        public static OrderStatus GetPendingStatus(this Table<OrderStatus> queriable)
        {
            return queriable.Single(status => status.StatusID == 1);
        }

        public static OrderStatus GetClosedStatus(this Table<OrderStatus> queriable)
        {
            return queriable.Single(status => status.StatusID == 2);
        }

        public static OrderStatus GetCanceledStatus(this Table<OrderStatus> queriable)
        {
            return queriable.Single(status => status.StatusID == 3);
        }

        public static OrderStatus GetAdjustedStatus(this Table<OrderStatus> queriable)
        {
            return queriable.Single(status => status.StatusID == 4);
        }

        public static bool IsValidToSell(this Table<OrderStatus> queriable, int orderStatusId)
        {
            if (_Canceled == null)
                _Canceled = GetCanceledStatus(queriable);
            if (_Adjusted == null)
                _Adjusted = GetAdjustedStatus(queriable);

            return orderStatusId != _Canceled.StatusID && orderStatusId != _Adjusted.StatusID;
        }
    }
}
